package testsuite;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Test;

public class testRegular {
	@Test
	public void a(){
		String sql = "update goods set name = 'pen',price=3 where id=1";
	    String pattern = "(?<=set)(.+)(?=where)";
	    Pattern p = Pattern.compile(pattern);
	    Matcher m = p.matcher(sql);
	    ArrayList<ArrayList<String>> changes = new ArrayList<ArrayList<String>>();
	    if (m.find( )) {
	    	  
	    	String changesString = m.group(0).replace("'", "").replace(" ", "");
	    	List<String> tempChanges = Arrays.asList(changesString.split(","));
		    for(int i=0;i<tempChanges.size();i++){
		    	ArrayList<String> AtempChange = new ArrayList(Arrays.asList(tempChanges.get(i).split("=")));
		    	AtempChange.add("=");
		    	changes.add(AtempChange);
		    }
		    
		   System.out.println(changes);
		    	
	    	  for(ArrayList<String> temp:changes){
	    		  System.out.println(temp);
//	    		  for(String t:temp){
//	    			  System.out.println(t);
//	    		  }
	    	  }
	    	  
//	    	  String columnsString = m.group(0).replace(" ", "").replace("'", "").replace("(", "").replace(")", "");
//	    	  System.out.println("Found value: " + columnsString );
//	    	  
//	    	  List<String> columns = Arrays.asList(columnsString.split(","));
//	    	  
//	    	  for(String temp:columns){
//	    		  System.out.println(temp);
//	    	  }
	         
	         
	      } else {
	         System.out.println("NO MATCH");
	      }
	}
	
	@Test
	public void b(){
		String conditionString = "a=2";
		
		
		String op = "";
		if(conditionString.indexOf("=")!=-1){
			op = "=";
		}
		if(conditionString.indexOf("<")!=-1){
			op = "<";
		}
		if(conditionString.indexOf(">")!=-1){
			op = ">";
		}
		if(conditionString.indexOf("<=")!=-1){
			op = "<=";
		}
		if(conditionString.indexOf(">=")!=-1){
			op = ">=";
		}
		System.out.println(op);
		ArrayList<String> AtempCondition = new ArrayList(Arrays.asList(conditionString.split(op)));
		AtempCondition.add(op);
		System.out.println(AtempCondition);
	}
	
	@Test
	public void c(){
		ArrayList<Integer> a = new ArrayList<Integer>();
		a.add(1);
		a.add(100);
		a.add(106);
		System.out.println(a.contains(100));
	}
	

}
